package com.sample.service.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.sample.model.User;
import com.sample.service.FlexService;
import com.sample.service.UserService;

import flex.messaging.FlexContext;

public class FlexServiceImpl implements FlexService {
	@Autowired
	private UserService userService;
	
	public void setUserDao(UserService userService) {
		this.userService = userService;
	}

	public User getCurrentUser() {
		if (FlexContext.getUserPrincipal() == null) return null;
		
		User user = userService.fetchUserByLogin(FlexContext.getUserPrincipal().getName());
		user.getRoles(); //fetch roles before losing Hibernate session
		return user;
	}
}
